<template>
    <div class="uploader-cert">
      <el-input v-model="props.modelValue" :placeholder="placeholder" disabled>
        <template #append>
          <el-upload action :http-request="uploadFile" :show-file-list="false" accept=".pem, .crt">
            <el-button type="primary">上传证书</el-button>
          </el-upload>
        </template>
      </el-input>
    </div>
  </template>
  <script>
    export default {
      name: 'UploaderCert',
    };
  </script>
  <script setup>

    import fileApi from '@/lnk/admin/api/index.js';
    import { ref, watch } from 'vue';
  
    const emit = defineEmits(['success',"update:modelValue"]);
    const props = defineProps(['modelValue', 'placeholder']);
  
   
    watch(
      () => props.modelValue,
      (val) => {
       console.log(1111,val)
        // emit('success', val);
      },
      {
      deep:true,
      immediate: true,
    }
    );
  
    async function uploadFile(file) {
      let formData = new FormData();
      formData.append('file', file.file);
      const { error, data } = await fileApi.upload.uploadCert(formData);
      if (error == 0) {
       
        
        emit('success', data.uri);
      }
    }
  </script>
  